<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>华鑫农业信息管理系统</title>
<link rel="stylesheet" type="text/css" href="../style/css.css">
<link href="http://cdn.bootcss.com/font-awesome/4.7.0/css/font-awesome.min.css" rel="stylesheet">
<link href="../style/search.css" rel="stylesheet">
<script language="javascript" type="text/javascript" src="../js/jquery1.4.min.js"></script>
<script language="javascript" type="text/javascript" src="../js/jquery.jslider.js"></script>
  <script src="../js/myScript/app.js"></script>
</head>
<body>
<div class="wrap">
  <jsp:include page="top.jsp"/>


  <div class="main">
<%--    产品分类--%>
    <jsp:include page="classify.jsp"/>

    <div class="mainr right">
      <h2><span class="ny_nav">您当前所在的位置：<a href="">首页</a> &gt; 产品展示</span>产品展示</h2>
      <div class="cp_list">
        <ul id="products">
          <li><a href="subcp.jsp">
            <p>产品名称：</p><br/>
            <p>产品价格：</p><br/>
            <p>产品公用：</p><br/>
            </a></li>

        </ul>
        <div class="clear"></div>
      </div>
    </div>
    <div class="clear"></div>
  </div>


  <jsp:include page="buttom.jsp"/>
</div>

<script type="text/javascript">

  $("#products").empty();
  $.ajax({
    type: "GET",
    url: serverUrl + "/product/queryProduct",
    dataType: "json",
    xhrFields: {
      withCredentials: true
    },
    success: function (res) {
      if (res.success) {
        var resData = res.data;
        for (var i = 0; i < resData.length; i++) {
          $("#products").append("<li><a onclick='skipProduct(this)' id=" + resData[i].ptId + ">\n" +
                  "            <p>产品名称："+ resData[i].ptName +"</p><br/>\n" +
                  "            <p>产品价格："+ resData[i].ptPrice+"（元/斤）</p><br/>\n" +
                  "            <p>产品功用："+ resData[i].ptValue+"</p><br/>\n" +
                  "            </a></li>");
        }
      }
    }
  });
  //点击分类查询，查询对应的产品并展示
  function queryByClass(element) {
    var classId = element.getAttribute("id");
    var queryUrl;
    if (classId == -1) {
      //查询所有
      queryUrl = serverUrl + "/product/queryProduct";
    } else {
      queryUrl = serverUrl + "/product/queryProductByClassifyId?tsId=" + classId;
    }

    $("#products").empty();
    $.ajax({
      type: "GET",
      url: queryUrl,
      dataType: "json",
      xhrFields: {
        withCredentials: true
      },
      success: function (res) {
        if (res.success) {
          var resData = res.data;
          for (var i = 0; i < resData.length; i++) {
            $("#products").append("<li><a  onclick='skipProduct(this)' id=" + resData[i].ptId + ">\n" +
                    "            <p>产品名称："+ resData[i].ptName +"</p><br/>\n" +
                    "            <p>产品价格："+ resData[i].ptPrice+"</p><br/>\n" +
                    "            <p>产品功用："+ resData[i].ptValue+"</p><br/>\n" +
                    "            </a></li>");
          }
        }
      }
    });
  }
  function skipProduct(element) {
    var id = element.getAttribute("id");
    window.location.href="subcp.jsp?id=" + id;
  }
</script>
</body>
</html>
